package xyz.zhzby.cyzx.judge.service.impl;

import org.springframework.beans.factory.annotation.Value;
import xyz.zhzby.cyzx.judge.entity.Submission;
import xyz.zhzby.cyzx.judge.mapper.SubmissionMapper;
import xyz.zhzby.cyzx.judge.service.ISubmissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 评测记录 服务实现类
 * </p>
 *
 * @author zby
 * @since 2022-02-03
 */
@Service
public class SubmissionServiceImpl extends ServiceImpl<SubmissionMapper, Submission> implements ISubmissionService {

    @Value("${judger.username}")
    private String judgerUsername;

    /**
     * @Param [submissionId, usedTime, usedMemory, score, judgeResult, log]
     * @Param [提交记录的ID, 提交运行使用时间(所有时间之和), 提交运行使用内存(最大内存占用), 运行得分, 运行结果(JudgeResultSlug), 运行日志记录]
     * @Return void []
     * @Author zby
     * @Date 2022/02/04
     * @Description 更新提交记录信息.
     */
    @Override
    public void updateSubmission(Long submissionId, int usedTime, int usedMemory, int score, String judgeResult, String log) {
        Submission submission = this.getById(submissionId);
        submission.setExecuteTime(new Date());
        submission.setUsedTime(usedTime);
        submission.setUsedMemory(usedMemory);
        submission.setJudgeScore(score);
        submission.setJudgeResult(judgeResult);
        submission.setJudgeLog(log);
        submission.setUpdateTime(new Date());
        submission.setUpdateUser(judgerUsername);
        this.saveOrUpdate(submission);
    }
    /**
     * @Param [submissionId, usedTime, usedMemory, score, judgeResult, log]
     * @Param [提交记录的ID, 提交运行使用时间(所有时间之和), 提交运行使用内存(最大内存占用), 运行得分, 运行结果(JudgeResultSlug), 运行日志记录]
     * @Return void []
     * @Author zby
     * @Date 2022/02/04
     * @Description 更新提交记录信息.
     */
    @Override
    public void updateSubmission(Long submissionId, int usedTime, int usedMemory, String log) {
        Submission submission = this.getById(submissionId);
        submission.setExecuteTime(new Date());
        submission.setUsedTime(usedTime);
        submission.setUsedMemory(usedMemory);
        submission.setJudgeLog(log);
        submission.setUpdateTime(new Date());
        submission.setUpdateUser(judgerUsername);
        this.saveOrUpdate(submission);
    }

}
